package com.cjj.mybatis.metahandler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Date 2021/11/03 11:54:56
 * @Created by BrownC_
 * @email ccc-ju@outlook.com
 */
@Component
public class DateMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.setInsertFieldValByName("gmtCreate", date, metaObject);
        this.setInsertFieldValByName("createTime", date, metaObject);
        this.setInsertFieldValByName("updateTime", date, metaObject);
        this.setInsertFieldValByName("gmtModified", date, metaObject);
        this.setInsertFieldValByName("gmtUpdate", date, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Date date = new Date();
        this.setUpdateFieldValByName("gmtModified", date, metaObject);
        this.setUpdateFieldValByName("updateTime", date, metaObject);
        this.setUpdateFieldValByName("gmtUpdate", date, metaObject);
    }
}
